package com.onstar.cn.api;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.enumtype.OSType;
import com.onstar.cn.sqlite.entities.RequestEventReportEntity;

import java.util.List;

/**
 * @Title: OperateReportService.java
 * @Description:事件上传report
 * @author Xiaofeng Feng
 * @date 2015年8月19日 下午2:15:18
 */
@Path("/msp/api/v3/public")
public class OperateReportService {
	/*
	 * [{"id":0,"functionID":"F0001","timestamp":"2015-07-28 16:47:08"
	 * ,"vin":"hhhhhhhh","operation":"click","startTimestamp":
	 * "2015-07-28 16:47:08","endTimestamp":"2015-07-28 16:47:08"
	 * ,"content":"content","role":"owner"},
	 * {"id":0,"functionID":"F0002","timestamp":"2015-07-28 16:47:08"
	 * ,"vin":"hhhhhhhh","operation":"click","startTimestamp":
	 * "2015-07-28 16:47:08","endTimestamp":"2015-07-28 16:47:08"
	 * ,"content":"content","role":"owner"}]
	 */
	private String serverURL;

	public OperateReportService(String serverURL) {
		this.serverURL = serverURL;
	}

	@RequestMapping("/report")
	public RequestEntity operateReport(RequestEntity requestEntity, RequestEventReportEntity EventReportList) {
		if (requestEntity == null) {
			requestEntity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "operateReport", requestEntity, EventReportList);

		requestEntity.setUrl(serverURL + url+"?OSType="+OSType.ANDROID.value());
		List<RequestEventReportEntity> list = EventReportList.getData();
		requestEntity.setBody(GsonHelper.toJson(list));
		LogManager.getInstance().d(requestEntity.getBody());
		return requestEntity;
	}
}
